﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Popup_Lobby_vs20Detail : Popup_Base
{
    const short SkillNum = 5;

    public Transform m_GraphRoot_Att;
    public Transform m_GraphRoot_Def;

    UISlider[] m_Graph_Att_On = new UISlider[SkillNum];
    UISlider[] m_Graph_Def_On = new UISlider[SkillNum];

    UISlider[] m_Graph_Att_Off = new UISlider[SkillNum];
    UISlider[] m_Graph_Def_Off = new UISlider[SkillNum];

    UILabel[] m_Value_Att_On = new UILabel[SkillNum];
    UILabel[] m_Value_Def_On = new UILabel[SkillNum];

    UILabel[] m_Value_Att_Off = new UILabel[SkillNum];
    UILabel[] m_Value_Def_Off = new UILabel[SkillNum];

    public override void AwakeInit()
    {
        Transform tempTr = null;
        Transform tempTr2 = null;
        for (int i = 0; i < SkillNum; i++)
        {
            tempTr = m_GraphRoot_Att.FindChild(string.Format("graph{0}", i + 1));
            tempTr2 = tempTr.FindChild("on");
            m_Graph_Att_On[i] = tempTr2.GetComponent("UISlider") as UISlider;
            m_Value_Att_On[i] = tempTr2.FindChild("value").GetComponent("UILabel") as UILabel;

            tempTr2 = tempTr.FindChild("off");
            m_Graph_Att_Off[i] = tempTr2.GetComponent("UISlider") as UISlider;
            m_Value_Att_Off[i] = tempTr2.FindChild("value").GetComponent("UILabel") as UILabel;

            tempTr = m_GraphRoot_Def.FindChild(string.Format("graph{0}", i + 1));
            tempTr2 = tempTr.FindChild("on");
            m_Graph_Def_On[i] = tempTr2.GetComponent("UISlider") as UISlider;
            m_Value_Def_On[i] = tempTr2.FindChild("value").GetComponent("UILabel") as UILabel;

            tempTr2 = tempTr.FindChild("off");
            m_Graph_Def_Off[i] = tempTr2.GetComponent("UISlider") as UISlider;
            m_Value_Def_Off[i] = tempTr2.FindChild("value").GetComponent("UILabel") as UILabel;
        }
    }
    
    public override void ButtonTouch(Collider collider)  // 버튼 터치 (터치 시작 끝 같은 오브젝트일때 터치 끝 시점에 호출)
    {
        if (collider.name == "Button_Back")
        {
            BackButton();
        }
    }

    public override void BackButton()
    {
        PopupManager.PopPopup();
    }


    // 인포 패널에 보여지는 순서
    AptitudeID_New[] m_ShowOrder = new AptitudeID_New[5]
    {
        AptitudeID_New.melee,
        AptitudeID_New.range,
        AptitudeID_New.magic,
        AptitudeID_New.pulse,
        AptitudeID_New.special       
    };


    public void SetPopupWithList(int[] skill_Att, int[] skill_Def,  int Max_Att, int Max_Def)
    { 
        for (int i = 0; i < SkillNum; i++)
        {
            if (Max_Att == 0)
            {
                m_Graph_Att_Off[i].value = 0;

                m_Graph_Att_On[i].gameObject.SetActive(false);
                m_Graph_Att_Off[i].gameObject.SetActive(true);

                Vector3 pos = m_Value_Att_Off[i].transform.localPosition;
                pos.x = m_Graph_Att_Off[i].foregroundWidget.localSize.x * m_Graph_Att_Off[i].value + 30;
                m_Value_Att_Off[i].transform.localPosition = pos;
            }
            else
            {
                //m_Graph_Att_On[i].gameObject.SetActive(Max_Att == skill_Att[i]);
                //m_Graph_Att_Off[i].gameObject.SetActive(Max_Att != skill_Att[i]);

                m_Graph_Att_On[i].value = skill_Att[i] / (float)Max_Att;
                m_Graph_Att_Off[i].value = skill_Att[i] / (float)Max_Att;

                if (Max_Att == skill_Att[i])
                {
                    m_Graph_Att_On[i].gameObject.SetActive(true);
                    m_Graph_Att_Off[i].gameObject.SetActive(false);

                    Vector3 pos = m_Value_Att_On[i].transform.localPosition;
                    pos.x = m_Graph_Att_On[i].foregroundWidget.localSize.x * m_Graph_Att_On[i].value + 30;
                    m_Value_Att_On[i].transform.localPosition = pos;
                }
                else
                {
                    m_Graph_Att_On[i].gameObject.SetActive(false);
                    m_Graph_Att_Off[i].gameObject.SetActive(true);

                    Vector3 pos = m_Value_Att_Off[i].transform.localPosition;
                    pos.x = m_Graph_Att_Off[i].foregroundWidget.localSize.x * m_Graph_Att_Off[i].value + 30;
                    m_Value_Att_Off[i].transform.localPosition = pos;
                }
            }

            


            if (Max_Def == 0)
            {                
                m_Graph_Def_Off[i].value = 0;

                m_Graph_Def_On[i].gameObject.SetActive(false);
                m_Graph_Def_Off[i].gameObject.SetActive(true);

                Vector3 pos = m_Value_Def_Off[i].transform.localPosition;
                pos.x = m_Graph_Def_Off[i].foregroundWidget.localSize.x * m_Graph_Def_Off[i].value + 30;
                m_Value_Def_Off[i].transform.localPosition = pos;
            }
            else
            {
                //m_Graph_Def_On[i].gameObject.SetActive(Max_Def == skill_Def[i]);
                //m_Graph_Def_Off[i].gameObject.SetActive(Max_Def != skill_Def[i]);

                m_Graph_Def_On[i].value = skill_Def[i] / (float)Max_Def;
                m_Graph_Def_Off[i].value = skill_Def[i] / (float)Max_Def;

                if (Max_Def == skill_Def[i])
                {
                    m_Graph_Def_On[i].gameObject.SetActive(true);
                    m_Graph_Def_Off[i].gameObject.SetActive(false);

                    Vector3 pos = m_Value_Def_On[i].transform.localPosition;
                    pos.x = m_Graph_Def_On[i].foregroundWidget.localSize.x * m_Graph_Def_On[i].value + 30;
                    m_Value_Def_On[i].transform.localPosition = pos;
                }
                else
                {
                    m_Graph_Def_On[i].gameObject.SetActive(false);
                    m_Graph_Def_Off[i].gameObject.SetActive(true);

                    Vector3 pos = m_Value_Def_Off[i].transform.localPosition;
                    pos.x = m_Graph_Def_Off[i].foregroundWidget.localSize.x * m_Graph_Def_Off[i].value + 30;
                    m_Value_Def_Off[i].transform.localPosition = pos;
                }
            }


            


            m_Value_Att_On[i].text = skill_Att[i].ToString();
            m_Value_Att_Off[i].text = skill_Att[i].ToString();
            m_Value_Def_On[i].text = skill_Def[i].ToString();
            m_Value_Def_Off[i].text = skill_Def[i].ToString();
        }
    }
}